package daoImpl;

import java.util.List;

import classes.Cliente;
import dao.IClienteDAO;

public class ClienteDAOImpl extends GenericDAOImpl<Cliente> implements IClienteDAO{


	//################### testar isso aqui ######################################
	@Override
	public void inserir(Cliente entidade) {
		this.getManager().getTransaction().begin();
		this.getManager().persist(entidade);
		this.getManager().getTransaction().commit();		
	}

	
	//################### rever isso aqui ######################################
	@Override
	public void atualizar(Cliente entidade) {
		this.getManager().getTransaction().begin();
		this.getManager().merge(entidade);
		this.getManager().getTransaction().commit();
		
	}

	@Override
	public void remover(long id) {
		Cliente cliente_encontrado = this.getManager().find(Cliente.class, id);
		this.getManager().getTransaction().begin();
		this.getManager().remove(cliente_encontrado);
		this.getManager().getTransaction().commit();		
	}

	@Override
	public List<Cliente> consultarTodos() {
		List<Cliente> lista = this.getManager().createQuery("select c from Cliente c").getResultList();
		return lista;
	}

	@Override
	public Cliente consultarPorId(long id) {
		Cliente cliente_encontrado = this.getManager().find(Cliente.class, id);
		return cliente_encontrado;
	}

}
